using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class NewUser : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }

    protected void btnLookupGroup_Click(object sender, EventArgs e)
    {
        string AffiliationKey = string.Empty;
        LMSData.Group org = new LMSData.Group();
        AffiliationKey = ((TextBox)CreateUserWizard1.WizardSteps[1].FindControl("txtGroupCode")).Text;
        if (AffiliationKey.Length > 0)
        {
            org = LMSData.GroupController.GetGroupByKey(AffiliationKey);
            if (org != null)
            {
                ((Label)CreateUserWizard1.WizardSteps[1].FindControl("lblGroupName")).Text = org.GroupName;
            }

        }
    }
    // CreatedUser event is called when a new user is successfully created
    public void CreateUserWizard1_CreatedUser(object sender, EventArgs e)
    {

        // Create an empty Profile for the newly created user
        ProfileCommon p = (ProfileCommon)ProfileCommon.Create(CreateUserWizard1.UserName, true);

        // Populate some Profile properties off of the create user wizard
        p.FirstName = ((TextBox)CreateUserWizard1.WizardSteps[0].FindControl("FirstName")).Text;
        p.LastName = ((TextBox)CreateUserWizard1.WizardSteps[0].FindControl("LastName")).Text;
        p.Address = ((TextBox)CreateUserWizard1.WizardSteps[0].FindControl("StreetAddress")).Text;
        p.City = ((TextBox)CreateUserWizard1.WizardSteps[0].FindControl("City")).Text;
        p.StateProvince = ((TextBox)CreateUserWizard1.WizardSteps[0].FindControl("StateProvince")).Text;
        p.PostalCode = ((TextBox)CreateUserWizard1.WizardSteps[0].FindControl("PostalCode")).Text;
        p.Country = ((TextBox)CreateUserWizard1.WizardSteps[0].FindControl("Country")).Text;
        p.Telephone = ((TextBox)CreateUserWizard1.WizardSteps[0].FindControl("PhoneNumber")).Text;
        p.Title = ((TextBox)CreateUserWizard1.WizardSteps[0].FindControl("JobTitle")).Text;
        p.CostCenter = ((TextBox)CreateUserWizard1.WizardSteps[0].FindControl("txtCostCenter")).Text;
        
        // Save the profile - must be done since we explicitly created this profile instance
        p.Save();

        // Associate user with group

        // TODO

        
    }

    // Activate event fires when the user hits "next" in the CreateUserWizard
    public void AssignUserToRoles_Activate(object sender, EventArgs e)
    {

        // Databind list of roles in the role manager system to a listbox in the wizard
        //AvailableRoles.DataSource = Roles.GetAllRoles(); ;
        //AvailableRoles.DataBind();
    }

    // Deactivate event fires when user hits "next" in the CreateUserWizard 
    public void AssignUserToRoles_Deactivate(object sender, EventArgs e)
    {

        // Add user to all selected roles from the roles listbox
        //for (int i = 0; i < AvailableRoles.Items.Count; i++)
        //{
        //   if (AvailableRoles.Items[i].Selected == true)
        //        Roles.AddUserToRole(CreateUserWizard1.UserName, AvailableRoles.Items[i].Value);
        //}
    }
}
